package com.py.credit.clean.code;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述: 处罚类别校验,允许多个处罚同时存在
 *
 * @author YaoS
 * @date 19/3/26 14:09
 */
public class PunishmentCategoryCheck {
    /**
     * 处罚类别字段
     */
    public static final String CF_CFLB = "CF_CFLB";
    public static final String CF_NR_FK = "CF_NR_FK";
    public static final String CF_NR_WFFF = "CF_NR_WFFF";
    public static final String CF_NR_ZKDX = "CF_NR_ZKDX";
    /**
     * 校验规则
     */
    public static final String A = "警告";
    public static final String B = "罚款";
    public static final String C = "没收违法所得、没收非法财物";
    public static final String D = "责令停产停业";
    public static final String E = "暂扣或者吊销许可证、暂扣或者吊销执照";
    public static final String F = "行政拘留";
    public static final String G = "其他-";

    public static boolean run(Map<String, Object> map, String extend) {
        if (StringUtils.isEmpty((String) map.get(CF_CFLB))) {
            return false;
        }
        try {
            return checkCflb((String) map.get(CF_CFLB), map);
        } catch (Exception e) {
            return false;
        }
    }

    private static boolean checkCflb(String data, Map<String, Object> map) {

         if (data.contains(B) && StringUtils.isEmpty((String) map.get(CF_NR_FK))&&Double.parseDouble((String) map.get(CF_NR_FK))>0) {
            return false;
            //如果包含没收违法所得，则CF_NR_WFFF不为空
        } else if (data.contains(C) && StringUtils.isEmpty((String) map.get(CF_NR_WFFF))&&Double.parseDouble((String) map.get(CF_NR_WFFF))>=0) {
            return false;
            //如果包含暂扣或吊销证照名称，则CF_NR_ZKDX不为空
        } else if (data.contains(E) && StringUtils.isEmpty((String) map.get(CF_NR_ZKDX))) {
            return false;
            //如果文本都不包含A~G
        } 
        return true;
    }

    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("CF_CFLB", "其他");
        map.put("CF_NR_FK", "100");
        map.put("CF_NR_WFFF", "HelloWorld");
        map.put("CF_NR_ZKDX", "HelloWorld");
        System.out.println(run(map, null));
    }

}
